- content_for :head do
  = stylesheet_link_tag     'multibox'
  = javascript_include_tag  'mootools-1.2.1-core.js'
  = javascript_include_tag  'mootools-1.2-more.js'
  = javascript_include_tag  'overlay-1.2.js'
  = javascript_include_tag  'multibox-1.4.js'
  %script{:type => "text/javascript"}
    ="  window.addEvent('domready', function(){box = new multiBox('mb', {descClassName: 'popup_box_content', overlay: new overlay()});});"
%div.gallery_title_container
  %div.gallery_title
    %h1.page_title=@gallery.name
  %div.gallery_description
    %p=@gallery.description
    - if @gallery.for_proofing?
      - if logged_in? and (@gallery.users.include?(current_user) or current_user.is_admin?)
        %div.view_approvals
          [
          %a{:href => gallery_approvals_url(@gallery), :title => "View the approvals for this gallery"}view approvals
          ]
%div.gallery_items
  - @gallery.all_items.each do |item|
    - if item.is_a?(Photo)
      - if @gallery.for_proofing?
        %table.photo{:class => (item.approved_in?(@gallery) ? "photo_approved" : ("photo_declined" if item.declined_in?(@gallery))), :id => "photo_approval_" + item.id.to_s}
          %tr
            %td.photo
              %a.mb{:href => item.public_filename(:screen), :rel => "width:800,height:600", :id => "photo_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                %img.photo_thumb{:src => item.public_filename(:thumb), :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
              %div{:class => "popup_box_content photo_#{item.id.to_s}", :id => "photo_#{item.id.to_s}_approval"}
                - unless @gallery.is_approved? or !logged_in?
                  - if current_user.authorized_to_view?(@gallery)
                    - if item.approved_in?(@gallery)
                      approve |
                      = link_to_remote "decline", :url => {:action => :decline, :controller => :approvals, :id => item.id, :approval => {:photo_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "photo_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Decline this photo", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('photo_approval_#{item.id.to_s}').removeClass('photo_approved'); $('photo_approval_#{item.id.to_s}').addClass('photo_declined')" : "box.next(); $('photo_approval_#{item.id.to_s}').removeClass('photo_approved'); $('photo_approval_#{item.id.to_s}').addClass('photo_declined')")}
                    - elsif item.declined_in?(@gallery)
                      = link_to_remote "approve", :url => {:action => :approve, :controller => :approvals, :id => item.id, :approval => {:photo_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "photo_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Approve this photo", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('photo_approval_#{item.id.to_s}').removeClass('photo_declined'); $('photo_approval_#{item.id.to_s}').addClass('photo_approved')" : "box.next(); $('photo_approval_#{item.id.to_s}').removeClass('photo_declined'); $('photo_approval_#{item.id.to_s}').addClass('photo_approved')")}
                      | decline
                    - else
                      = link_to_remote "decline", :url => {:action => :decline, :controller => :approvals, :id => item.id, :approval => {:photo_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "photo_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Decline this photo", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('photo_approval_#{item.id.to_s}').removeClass('photo_approved'); $('photo_approval_#{item.id.to_s}').addClass('photo_declined')" : "box.next(); $('photo_approval_#{item.id.to_s}').removeClass('photo_approved'); $('photo_approval_#{item.id.to_s}').addClass('photo_declined')")}
                      |
                      = link_to_remote "approve", :url => {:action => :approve, :controller => :approvals, :id => item.id, :approval => {:photo_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "photo_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Approve this photo", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('photo_approval_#{item.id.to_s}').removeClass('photo_declined'); $('photo_approval_#{item.id.to_s}').addClass('photo_approved')" : "box.next(); $('photo_approval_#{item.id.to_s}').removeClass('photo_declined'); $('photo_approval_#{item.id.to_s}').addClass('photo_approved')")}  
                - else
                  - if item.approved_in?(@gallery)
                    This photo was approved.
                  - elsif item.declined_in?(@gallery)
                    This photo was declined.
                  - else
                    This item was not reviewed.
      - else
        %table.photo
          %tr
            %td.photo
              %a.mb{:href => item.public_filename(:screen), :rel => "width:800,height:600", :id => "photo_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                %img.photo_thumb{:src => item.public_filename(:thumb), :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
              %div{:class => "popup_box_content photo_#{item.id.to_s}", :id => "photo_#{item.id.to_s}_description"}
                - if item.is_purchasable? and @gallery.purchasable?
                  - if logged_in?
                    - if current_user.has_in_cart?(item)
                      This photo is already
                      %a{:href => orders_url, :title => "Your shopping cart"} your cart.
                      You can 
                      = link_to_remote "add it again", :url => {:action => :create, :controller => :items, :render => :partial, :item => {:photo_id => item.id}, :gallery_id => @gallery.id}, :update => "photo_#{item.id.to_s}_description", :html => {:class => "MultiBoxCloseFromLink", :title => "Add this photo to your shopping cart", :onclick => ((item == @gallery.all_items.last) ? "box.close()" : "box.next()")}
                      if you like
                      %a{:href => orders_url, :title => "Your shopping cart"}
                    - else
                      = link_to_remote "add to cart", :url => {:action => :create, :controller => :items, :render => :partial, :item => {:photo_id => item.id}, :gallery_id => @gallery.id}, :update => "photo_#{item.id.to_s}_description", :html => {:class => "MultiBoxCloseFromLink", :title => "Add this photo to your shopping cart", :onclick => ((item == @gallery.all_items.last) ? "box.close()" : "box.next()")}
                  - else
                    Want to purchase this photo?
                    %a{:href => login_url, :title => "Login"}Login
                    or
                    %a{:href => signup_url, :title => "Signup"}signup
                    to add it to your cart.
    - if item.is_a?(Video)
      - if @gallery.for_proofing?
        %table.video{:class => (item.approved_in?(@gallery) ? "video_approved" : ("video_declined" if item.declined_in?(@gallery))), :id => "video_approval_" + item.id.to_s}
          %tr
            %td.video
              %a.mb{:href => item.public_filename, :rel => "width:853,height:496", :id => "video_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                %img.video_thumb{:src => item.thumbnail, :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
              %div{:class => "popup_box_content video_#{item.id.to_s}", :id => "video_#{item.id.to_s}_approval"}
                - unless @gallery.is_approved? or !logged_in?
                  - if current_user.authorized_to_view?(@gallery)
                    - if item.approved_in?(@gallery)
                      approve |
                      = link_to_remote "decline", :url => {:action => :decline, :controller => :approvals, :id => item.id, :approval => {:video_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "video_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Decline this video", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('video_approval_#{item.id.to_s}').removeClass('video_approved'); $('video_approval_#{item.id.to_s}').addClass('video_declined')" : "box.next(); $('video_approval_#{item.id.to_s}').removeClass('video_approved'); $('video_approval_#{item.id.to_s}').addClass('video_declined')")}
                    - elsif item.declined_in?(@gallery)
                      = link_to_remote "approve", :url => {:action => :approve, :controller => :approvals, :id => item.id, :approval => {:video_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "video_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Approve this video", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('video_approval_#{item.id.to_s}').removeClass('video_declined'); $('video_approval_#{item.id.to_s}').addClass('video_approved')" : "box.next(); $('video_approval_#{item.id.to_s}').removeClass('video_declined'); $('video_approval_#{item.id.to_s}').addClass('video_approved')")}
                      | decline
                    - else
                      = link_to_remote "decline", :url => {:action => :decline, :controller => :approvals, :id => item.id, :approval => {:video_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "video_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Decline this video", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('video_approval_#{item.id.to_s}').removeClass('video_approved'); $('video_approval_#{item.id.to_s}').addClass('video_declined')" : "box.next(); $('video_approval_#{item.id.to_s}').removeClass('video_approved'); $('video_approval_#{item.id.to_s}').addClass('video_declined')")}
                      |
                      = link_to_remote "approve", :url => {:action => :approve, :controller => :approvals, :id => item.id, :approval => {:video_id => item.id, :gallery_id => @gallery.id, :user_id => current_user.id}}, :update => "video_#{item.id.to_s}_approval", :html => {:class => "MultiBoxCloseFromLink", :title => "Approve this video", :onclick => ((item == @gallery.all_items.last) ? "box.close(); $('video_approval_#{item.id.to_s}').removeClass('video_declined'); $('video_approval_#{item.id.to_s}').addClass('video_approved')" : "box.next(); $('video_approval_#{item.id.to_s}').removeClass('video_declined'); $('video_approval_#{item.id.to_s}').addClass('video_approved')")}
                - else
                  - if item.approved_in?(@gallery)
                    This video was approved.
                  - elsif item.declined_in?(@gallery)
                    This video was declined.
                  - else
                    This video was not reviewed.
      - else
        %table.video
          %tr
            %td.video
              %a.mb{:href => item.public_filename, :rel => "width:853,height:496", :id => "video_#{item.id.to_s}", :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
                %img.video_thumb{:src => item.thumbnail, :title => (item.caption ? item.caption : item.filename), :alt => (item.caption ? item.caption : item.filename)}
              %div{:class => "popup_box_content video_#{item.id.to_s}", :id => "video_#{item.id.to_s}_description"}
                - if item.is_purchasable? and @gallery.purchasable?
                  - if logged_in?
                    - if current_user.has_in_cart?(item)
                      This video is already in
                      %a{:href => orders_url, :title => "Your shopping cart"} your cart.
                      You can 
                      = link_to_remote "add it again", :url => {:action => :create, :controller => :items, :render => :partial, :item => {:video_id => item.id}, :gallery_id => @gallery.id}, :update => "video_#{item.id.to_s}_description", :html => {:class => "MultiBoxCloseFromLink", :title => "Add this photo to your shopping cart", :onclick => ((item == @gallery.all_items.last) ? "box.close()" : "box.next()")}
                      if you like
                    - else
                    = link_to_remote "add to cart", :url => {:action => :create, :controller => :items, :render => :partial, :item => {:video_id => item.id}, :gallery_id => @gallery.id}, :update => "video_#{item.id.to_s}_description", :html => {:class => "MultiBoxCloseFromLink", :title => "Add this video to your shopping cart", :onclick => ((item == @gallery.all_items.last) ? "box.close()" : "box.next()")}
                  - else
                    Want to purchase this video?
                    %a{:href => login_url, :title => "Login"}Login
                    or
                    %a{:href => signup_url, :title => "Signup"}signup
                    to add it to your cart.
%div.pagination
  = will_paginate @gallery.all_items